package com.sb.money.components;

import java.util.ArrayList;
import java.util.List;

import org.apache.tapestry5.Asset;
import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.annotations.BeginRender;
import org.apache.tapestry5.annotations.Component;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Path;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.corelib.components.Form;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.json.JSONArray;
import org.apache.tapestry5.json.JSONObject;
import org.apache.tapestry5.services.javascript.JavaScriptSupport;

/**
 * ListDialog component which is a List component with CRUD buttons for
 * create/update/delete items in the list. The changes are then save or canceled
 * by the form buttons.
 * 
 * @author Stefan Bertos
 */
public class ListDialog {
    
    /**
     * inject the component form.
     */
    @Component(id = "listDialog")
    private Form form;
    

    @Property
    private List<Object> items;

    @Property
    private Object item;
    
    @Inject
    @Path("context:images/Crystal_Clear_action_db_add.png")
    @Property
    private Asset createImage;
    
    @Inject
    @Path("context:images/Crystal_Clear_action_db_comit.png")
    @Property
    private Asset updateImage;
    
    @Inject
    @Path("context:images/Crystal_Clear_action_db_remove.png")
    @Property
    private Asset deleteImage;
    
    @Property
    private String nameUpdate;
    @Property
    private String nameCreate;
    
    @Property
    private JSONObject deleteDialogParams;
    
    @Property
    private JSONObject updateDialogParams;
    //http://api.jqueryui.com/dialog/
    
    /**
     * Default constructor.
     */
    public ListDialog() {
    }
    
    @Inject
    private JavaScriptSupport javaScriptSupport;
    
    @BeginRender
    void begin() {
        updateDialogParams = new JSONObject();
        deleteDialogParams = new JSONObject();
        
        deleteDialogParams.put("resizable", "false");
        deleteDialogParams.put("height", "140");
        deleteDialogParams.put("width", "300");
        
        deleteDialogParams.put("modal", "true");
        
        updateDialogParams.put("resizable", "false");
        updateDialogParams.put("height", "110");
        updateDialogParams.put("width", "235");
        updateDialogParams.put("modal", "true");
        
        
        JSONArray deleteDialogButtons = new JSONArray();
        final JSONObject result1 = new JSONObject();
        
        final JSONObject result2 = new JSONObject();        
        result1.put("text","Delete item");
        result1.put("click", null);
        result1.put("id", "button1");
        
        
        result2.put("text", "Cancel");
        result2.put("click", "button2click");
        result2.put("id", "button2");
        
        
        deleteDialogButtons.put(result1);
        deleteDialogButtons.put(result2);
        
        deleteDialogParams.put("buttons", deleteDialogButtons);
        
        
        items = new ArrayList<Object>();
        items.add("ssss1");
        items.add("ssss2");
        items.add("ssss3");
        items.add("ssss4");
        items.add("ssss5");
        
     }
    
  public void onButton1() {
      
  }
  
  public void onButton2() {
      
  }
  
    
}
